import { createRouter,createWebHistory } from "vue-router";

const router=createRouter({
    history:createWebHistory(import.meta.env.BASE_URL),
    routes:[
        { path: '/', name: 'Login', component: () => import('../views/Login.vue') },
        {path:'/Manger',name:'Manger',component:()=>import('../views/Manger.vue'),children:[
            {path:'data',name:'data',component:()=>import('../views/data.vue')},
            {path:'work',name:'work',component:()=>import('../views/work.vue')},
    ]}
    ]
})

router.beforeEach((to, from, next) => {
    //to到哪儿  from从哪儿离开  next跳转 为空就是放行  
        if (to.path === '/') {
            //如果跳转为登录，就放行 
            next();    
        } else {
        //取出sessionStorage判断
              let token = sessionStorage.getItem('token');      	     
              if (token == null || token === '') { 
                     console.log('请先登录')       
                     next({name: 'Login'});
                 } else {
                        next();   
                 }   
    }});

export default router